package tuan.filter;

import java.util.*;

import org.w3c.dom.*;

import tuan.travel.TravelCallback;

public class TravelFilterChain implements TravelCallback {

	List<NodeFilter> filterList = new ArrayList<NodeFilter>();
	List<Node> nodeList = new ArrayList<Node>();

	public List<Node> getNodeList() {
		return nodeList;
	}

	public void callback(Node root, Node node) throws Exception {
		if (root == null || node == null) {
			throw new Exception("null arguments");
		}
		for (NodeFilter filter : filterList) {
			if (!filter.isValid(node)) {
				return;
			}
		}
		nodeList.add(node);
	}

	public TravelFilterChain addFilter(NodeFilter filter) {
		filterList.add(filter);
		return this;
	}

	public TravelFilterChain clear() {
		filterList.clear();
		return this;
	}

}
